package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsUserMapper;
import com.qf.pojo.DtsUser;
import com.qf.vo.DayStatis;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/18 16:48
 */
@Service
public class UserServiceImpl  implements  UserService{

    @Autowired
    private DtsUserMapper mapper;

    @Override
    public int countUser() {
        QueryWrapper<DtsUser> objectQueryWrapper = new QueryWrapper<>();
        objectQueryWrapper.eq("deleted", false);
        Integer integer = mapper.selectCount(objectQueryWrapper);


        return integer;
    }

    @Override
    public List<DayStatis> incrCount() {

        List<DayStatis> dayStatis = mapper.staticIncreaseUser();
        return dayStatis;
    }

    /**
     * 查询所有用户
     * @param username
     * @param mobile
     * @param page
     * @param limit
     * @param sort
     * @param desc
     * @return
     */
    @Override
    public IPage<DtsUser> findUserAll(String username, String mobile, Integer page, Integer limit, String sort, String desc) {
          IPage page1=new Page<>(page,limit);
           //得到分页对象
         List records = page1.getRecords();
           //创建条件对象
        QueryWrapper<DtsUser> objectQueryWrapper = new QueryWrapper<>();

         objectQueryWrapper.eq("deleted", false);
         if(!StringUtils.isEmpty(username)){
             objectQueryWrapper.eq("username", username);
         }
         if(!StringUtils.isEmpty(mobile)){
             objectQueryWrapper.eq("mobile", mobile);
         }
         if(!StringUtils.isEmpty(sort)&&!StringUtils.isEmpty(desc)){
              if(sort.equalsIgnoreCase("asc")){
                  objectQueryWrapper.orderByAsc();
              }else {
                  objectQueryWrapper.orderByDesc();
              }
         }
          //得到分页集合对象
        IPage<DtsUser> iPage = mapper.selectPage(page1, objectQueryWrapper);

        return iPage;
    }


}
